package com.demonzym.framework.activitymanager;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;

import com.demonzym.R;
import com.demonzym.framework.application.MyApplication;
import com.demonzym.framework.log.MyLog;
import com.demonzym.framework.skinmanager.ChangeSkinInterface;
import com.demonzym.framework.widget.MyDialog;

/**
 * base activity
 * @author Administrator
 *
 */
public class ActivityBase extends FatherSonActivityMgr implements ChangeSkinInterface{
	private ProgressDialog mWaitingProgress;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		NormalActivityManager.getInstance().addActivity(this);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		requestFeature();
		
		super.setContentView(R.layout.main);
		
	}
		
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		
		if(resultCode != Activity.RESULT_OK)
			return;
				
	}
	
	@Override
	protected void onDestroy() {
		NormalActivityManager.getInstance().removeActivity(this);
		super.onDestroy();
		
	}	
	
	protected void requestFeature(){
		
	}
		    
	@Override
	public void setContentView(int layoutResID) {
		LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(layoutResID,  null, false);
		setContentView(v);
	}
	
	protected void waitingSomething(String message){
		waitingSomething(null, message);
	}
	
	protected void waitingSomething(String title, String message){
		if(mWaitingProgress != null)
			stopWaiting();
		
		MyLog.i("ActivityBase", "waiting:" + this.toString() );
		mWaitingProgress = MyDialog.showProgressDialog(this, title, message, true, true);
	}
	protected void stopWaiting(){
		if(mWaitingProgress != null){
			MyLog.i("ActivityBase", "stop waiting:" + this.toString() );
			mWaitingProgress.dismiss();
			mWaitingProgress = null;
		}
	}
	protected boolean isWaiting(){
		return (mWaitingProgress != null);
	}
		
	public void OnChangeSkin(int skinId) {
		// TODO Auto-generated method stub
	}

	public void finishApplication(){
		MyApplication.getAppInstance().finishApp();
	}
}
